<?php
/**
 * Created by JetBrains PhpStorm.
 * User: scala
 * Date: 12-10-28
 * Time: 上午11:12
 * To change this template use File | Settings | File Templates.
 */
class CaseImgAction extends CommonAction
{

    function delete(){
        if(!empty($_GET["id"])){
            $caseImg=M("CaseImg");
            $caseImg->delete($_GET['id']);
            $this->success("删除成功！");
        }else{
            $this->error("删除失败！");
        }
    }


    function setMainImg(){
        if(!empty($_GET["id"])&&!empty($_GET["caseid"])){
            $caseImg=M("CaseImg");
            $caseImg->startTrans();
            $selectData["caseid"]=$_GET['caseid'];
            $selectData["mainimg"]=array("eq",1);
            $caseImg->where($selectData)->data(array("mainimg"=>0))->save();
            $data["id"]=$_GET['id'];
            $data["mainimg"]=1;
            $caseImg->data($data)->save();
            $caseImg->commit();
            $this->success("设置主图成功！");
        }else{
            $this->error("设置主图失败！");
        }
    }


    function sortNumber(){
        if(!empty($_GET["id"])&&!empty($_GET["sort"])){
            $caseImg=M("CaseImg");
            $data["sort"]=$_GET["sort"];
            $data["id"]=$_GET["id"];
            $caseImg->save($data);
            $this->success("修改排序成功！");
        }else{
            $this->error("修改排序失败！");
        }
    }
}
